<template>
    <Card>
      <VerticalToggle>
        <MldSearch ref="search" v-if="searchable" class="search" @on-search="handleSearch(...arguments, vm)"></MldSearch>
      </VerticalToggle>
     <Table
     @on-selection-change='handleSelectionChange(...arguments, vm)'
     :loading="loading" stripe :columns="columns" :data="tableData"></Table>
      <Page class="mld-page"
      :current='pageIndex'
      :page-size='pageSize'
      @on-change='handlePageIndexChange(...arguments, vm)'
      @on-page-size-change='handlePageSizeChange(...arguments, vm)'
      show-total
      show-elevator
      show-sizer
      transfer
      style="margin-top:10px;"
      :prev-text="vm.$t('prev-text')" :next-text="vm.$t('next-text')" :total="recordCount"></Page>
    </Card>
</template>

<script>
import MldSearch from './components/search'
import methods from './methods'
import { saveAdminRole } from '@/api/sys/sys.rbac.service'
export default {
  components: {
    MldSearch
  },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    },
    params: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      modalAdd: true,
      searchable: true,
      fullscreen: false,
      loading: false,
      pageIndex: this.$config.pageIndex,
      pageSize: this.$config.pageSize,
      recordCount: 0,
      selection: [],
      columns: [
        {type: 'selection', width: 60, align: 'center'},
        {
          title: '登录名',
          key: 'userName',
          render: (h, params) => {
            return h('div', params.row.userName)
          }
        },
        {
          title: '姓名',
          key: 'realName',
          render: (h, params) => {
            return h('div', params.row.realName)
          }
        },
        {
          title: '手机号',
          key: 'mobilePhone',
          render: (h, params) => {
            return h('div', params.row.mobilePhone)
          }
        },
        {
          title: '创建时间',
          key: 'createTime',
          width: 150,
          render: (h, params) => {
            return h('div', params.row.createTime)
          }
        }
      ],
      tableData: []
    }
  },
  created () {
    this.vm = this
  },
  methods: Object.assign({}, methods, {
    // ...methods,
    submit () {
      return new Promise((resolve, reject) => {
        var ids = this.selection.map(item => {
          return item.id
        })
        if (!ids.length) {
          reject(new Error('至少选一条'))
        } else {
          saveAdminRole({
            roleId: this.params.id,
            adminIds: ids
          }).then(res => {
            resolve(res)
          }).catch(e => {
            reject(e)
          })
        }
      })
    }
  }),
  mounted () {
    this.requestData(this)
  }
}
</script>

<style>
</style>
